package pkg.genericity.business;
/**
 * 
 * @author Farrukh Shakil
 * Business Object 
 */
import java.util.List;

import pkg.genericity.DAO.BeanDAO;

public class BeanBO {
	
	private Class<?> clazz;

	/**
	 * Persists an object to database
	 * @param object
	 * @return
	 */
	public Boolean addBean(Object object) {
		return new BeanDAO().addBean(object);
	}
	
	/**
	 * Gets all beans that are instances of of the given class
	 * @param clazz
	 * @return
	 */
	public List<Object> getBeans(Class<?> clazz) {
		return new BeanDAO().getBeans(clazz);
	}
	
	/**
	 * Get records as they appear in database along with the column headers as first record
	 * @param clazz
	 * @return
	 */
	public List<Object[]> getRecords(Class<?> clazz) {
		return new BeanDAO().getRecords(clazz, true);
	}
	
	/**
	 * Get all beans. (Prereq: setClassName(classname) or setClass(class) method already called to set the class name)
	 * @return
	 */
	public List<Object> getBeans() {
		return (clazz!=null)?new BeanDAO().getBeans(clazz):null;
	}
	
	public List<Object[]> getRecords() {
		return (clazz!=null)?new BeanDAO().getRecords(clazz, true):null;
	}

	public void setClassName(String classname) {
		try {
			this.clazz = Class.forName(classname);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public void setClass(Class<?> clazz) {
		this.clazz = clazz;
	}
	

}
